<?php

class CpcurrencyController extends Core_Controller_Action 
{
	private $_api;
	
	public function init() {	
		$this->_api = new Currency();	
	}
	public function indexAction(){
		$page = intval( $this->_request->getParam( 'page', 1 ) );
		
		$pagerLayout = $this->_api->getListWithPager( $page, $this->view->baseUrl() );
		
		$this->view->list = $pagerLayout->execute();
		$this->view->pager = $pagerLayout;
	}
	public function addAction(){
		$id = intval( $this->_request->getParam( 'id', 0 ) );
		if($this->_request->isPost())
		{
			if($id)
				$currency = $this->_api->getItem( $id )->getFirst();
			else
				$currency = $this->_api;
			$currency->name = $this->_getParam('name');
			$currency->save();
			$this->_redirect('cpcurrency');
		}
		if($id)
		{
			$currency = $this->_api->getItem( $id )->getFirst()->toArray();
			$this->view->currency = $currency;
		}
	}
	public function deleteAction(){
		$id = intval( $this->_request->getParam( 'id', 0 ) );
		if($id)
			$this->_api->deleteItem($id);
		$this->_redirect('cpcurrency');
	}
}
	